package service;

import dao.UserDao;
import entity.mvc.User;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: SSM201759225309
 * @description:
 * @author: Xiaozhuoer
 * @create: 2021-05-07 13:16
 **/

@Service
public class UserManageService {

    private final UserDao userDao;

    public UserManageService(UserDao userDao){
        this.userDao = userDao;
    }

    public Result logonUser(User user){
        Result result = new Result();
        int affectedRowCount = userDao.logonUser(user);
        if(affectedRowCount == 1){
            result.setStatus(0);
            result.setMsg("用户注册成功");
        }else{
            result.setMsg("用户注册失败");
        }
        return result;
    }

    public Result loginUser(User user) {
        Result result = new Result();
        int affectedRowCount = userDao.loginUser(user);
        if(affectedRowCount == 1){
            result.setStatus(0);
            result.setMsg("用户登录成功");
        }else{
            result.setMsg("用户登录失败");
        }
        return result;
    }
    public Result addUser(User user){
        Result result = new Result();
        int affectedRowCount = userDao.addUser(user);
        if(affectedRowCount == 1){
            result.setStatus(0);
            result.setMsg("添加用户成功");
        }else{
            result.setMsg("添加用户失败");
        }
        return result;
    }
    public Result findUser(User user){
        Result result = new Result();
        List<User> users = userDao.findUser(user);
        return result;
    }
    public Result updateUserInfo(User user){
        Result result = new Result();
        int affectedRowCount = userDao.updateUserInfo(user);
        if(affectedRowCount == 1){
            result.setStatus(0);
            result.setMsg("修改用户信息成功");
        }else{
            result.setMsg("修改用户信息失败");
        }
        return result;
    }
    public Result deleteUser(User user){
        Result result = new Result();
        userDao.deleteUser(user);
        result.setMsg("删除用户完成");
        return result;
    }

}
